import { setTimeout } from "core-js";
import axios from "axios";

export default {
  // 开启命名空间
  namespaced: true,
  //<!-- 在.vue文件中通过this.$store.state.xxx来进行获取 -->
  state: {
    name: "赵杨",
    //控制切换到知识对战 开屏显示的图片
    ImgShow: true,
    ImgShow2: true,
    //登录页
    password: "",
    username: "",
    list: [],
    message: "",
  },
  getters: {
    newName(state) {
      return state.name + "的模块";
    },
  },
  mutations: {
    CHANGE_NAME(state) {
      state.name = "被修改了";
    },
    //知识对战
    Img_Show(state) {
      state.ImgShow = false;
    },
    Is_Show(state) {
      state.ImgShow2 = false;
    },
  },
  actions: {
    //知识对战
    init(context) {
      setTimeout(() => {
        context.commit("Img_Show");
      }, 1500);
    },
    //请求登录接口
    async LOGIN(context, { param }) {
      const Login = await axios.post("/user/login", param);
      const token = Login.data.tokenHead + Login.data.token;
      localStorage.setItem("Token", token);
      if (Login.code == 200) {
        const UserInfo = await axios.get("/user/info", param.username);
      }
    },

    //发送验证码
    SENDCODE(context, { formData }) {
      axios
        .post("/user/verificationCodeSend", formData)
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //用户验证码注册
    UESRCODEREG(context, { param }) {
      axios
        .post("/user/registerVerificationCode", param)
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    RETRIEVE(context, { param }) {
      axios
        .post("/user/updatePassword", param)
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
